import { csstockedit, outputcs } from '@/api/mupro'

const save = async (
  result: Array<any>,
  type: string,
  multipleSelection: Array<any>
) => {
  let fun: any
  const params: any = {}
  switch (type) {
    case 'add':
      fun = csstockedit
      result.map((item: any) => {
        params[item.field] = item.model
      })
      params.status = params.status ? 1 : 0
      if (multipleSelection && multipleSelection.length) {
        params.ID = multipleSelection[0].ID
      } else {
        params.ID = 0
      }
      break
    case 'out':
      fun = outputcs
      result.map((item: any) => {
        params[item.field] = item.model
      })
      params.cslist = multipleSelection
        .map((item: any) => {
          return item.UUID
        })
        .join(',')
  }
  const { data, code } = await fun(params)
  return {
    data,
    code,
  }
}

export { save }
